import json
import requests

# 替换以下变量的值
# FEISHU_APP_ID: 飞书应用的ID
# FEISHU_APP_SECRET: 飞书应用的密钥
# FEISHU_ENDPOINT: 要调用的API端点
FEISHU_APP_ID = 'cli_a79a71dbee3c500b'
FEISHU_APP_SECRET = 'So56AEs03QtIWYqajoGhFfqLTJy2Zq3q'
FEISHU_ENDPOINT = 'https://open.feishu.cn/open-apis/im/v1/messages'

# 获取Access Token
data = {
    'app_id': FEISHU_APP_ID,
    'app_secret': FEISHU_APP_SECRET
}
response = requests.post('https://open.feishu.cn/open-apis/auth/v3/tenant_access_token/internal', json=data)
access_token = response.json()['tenant_access_token']
print(access_token)

url = "https://open.feishu.cn/open-apis/im/v1/messages"
params = {"receive_id_type": "user_id"}
msg = "ni hao dfafdsd"
msgContent = {
    "text": msg,
}
req = {
    "receive_id": "be686694",  # chat id
    "msg_type": "text",
    "content": json.dumps(msgContent)
}
payload = json.dumps(req)
headers = {
    'Authorization': f'Bearer {access_token}',
    'Content-Type': 'application/json'
}

response = requests.request("POST", url, params=params, headers=headers, data=payload)
print(response.headers['X-Tt-Logid'])  # for debug or oncall
print(response.content)  # Print Response
